# __init__.py 为初始化加载文件
import time

# 导入系统资源模块
from ascript.android.system import R
# 导入动作模块
from ascript.android import action
# 导入节点检索模块
from ascript.android import node
# 导入图色检索模块
from ascript.android import screen
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
from airscript.action import click
from ascript.android.ui import Dialog



# res = FindImages.find_all([R.img("1.png"),],confidence= 0.8)
# print(res)
# if res:
#     # 遍历所有 找到的结果
#     for i in res:
#         print("中心坐标:",i["center_x"],i["center_y"])
#         print("相似度:",i["confidence"])
#         print("在屏幕中的范围:",i["rect"])
#     click(i["center_x"],i["center_y"])
#     time.sleep(2)

while True:
    # 展示一个简单吐司提示,3秒后消失,位置偏屏幕中心点 y坐标+20%屏幕高度
    Dialog.toast('保持在兑换界面，正在运行中...',3000,-1,-1)
    # 点击兑换
    res2 = FindImages.find_all([R.img("222.png"),],confidence= 0.8)
    # print(res2)
    if res2:
        # 遍历所有 找到的结果
        for i in res2:
            print("中心坐标:",i["center_x"],i["center_y"])
            print("相似度:",i["confidence"])
            print("在屏幕中的范围:",i["rect"])
        click(i["center_x"],i["center_y"])
        time.sleep(0.3)

    # 点击确认兑换
    res3 = FindImages.find_all([R.img("333.png"),],confidence= 0.8)
    # print(res3)
    if res3:
        # 遍历所有 找到的结果
        for i in res3:
            print("中心坐标:",i["center_x"],i["center_y"])
            print("相似度:",i["confidence"])
            print("在屏幕中的范围:",i["rect"])
        click(i["center_x"],i["center_y"])
        time.sleep(0.3)




